<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>NSData理解与进阶 | Albert Yuan's Blog</title><meta name="keywords" content="iOS"><meta name="author" content="Albert Yuan"><meta name="copyright" content="Albert Yuan"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#0d0d0d"><meta name="referrer" content="no-referrer"><meta name="description" content="NSData1.概念 NSData为二进制数据，在文件操作（如保存到本地）、网络、以及核心图形图像中使用较广泛。  源码： 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737">
<meta property="og:type" content="article">
<meta property="og:title" content="NSData理解与进阶">
<meta property="og:url" content="https://yllove.gitee.io/2021/12/10/iOS/NSData%E7%90%86%E8%A7%A3%E4%B8%8E%E8%BF%9B%E9%98%B6/index.html">
<meta property="og:site_name" content="Albert Yuan&#39;s Blog">
<meta property="og:description" content="NSData1.概念 NSData为二进制数据，在文件操作（如保存到本地）、网络、以及核心图形图像中使用较广泛。  源码： 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://yllove.gitee.io/img/defaultCover.png">
<meta property="article:published_time" content="2021-12-10T01:49:42.099Z">
<meta property="article:modified_time" content="2021-12-10T03:17:24.764Z">
<meta property="article:author" content="Albert Yuan">
<meta property="article:tag" content="iOS">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://yllove.gitee.io/img/defaultCover.png"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="https://yllove.gitee.io/2021/12/10/iOS/NSData%E7%90%86%E8%A7%A3%E4%B8%8E%E8%BF%9B%E9%98%B6/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://fastly.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://fastly.jsdelivr.net/npm/instantsearch.js@2.10.5/dist/instantsearch.min.css" media="print" onload="this.media='all'"><script src="https://fastly.jsdelivr.net/npm/instantsearch.js@2.10.5/dist/instantsearch.min.js" defer></script><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: {"appId":"X8NS0XSX99","apiKey":"b9d4530647c8b5bf7928a04c47752ad7","indexName":"albertyuan","hits":{"per_page":6},"languages":{"input_placeholder":"搜索文章","hits_empty":"找不到您查询的内容：${query}","hits_stats":"找到 ${hits} 条结果，用时 ${time} 毫秒"}},
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://fastly.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://fastly.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://fastly.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://fastly.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://fastly.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: true,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'NSData理解与进阶',
  isPost: true,
  isHome: false,
  isHighlightShrink: true,
  isToc: true,
  postUpdate: '2021-12-10 11:17:24'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.2.0"><link rel="alternate" href="/blog/atom.xml" title="Albert Yuan's Blog" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/blog/img/favicon.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">155</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">56</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">32</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/blog/img/defaultCover.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">Albert Yuan's Blog</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">NSData理解与进阶</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-12-10T01:49:42.099Z" title="发表于 2021-12-10 09:49:42">2021-12-10</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-12-10T03:17:24.764Z" title="更新于 2021-12-10 11:17:24">2021-12-10</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.7k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>11分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="NSData理解与进阶"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h5 id="NSData"><a href="#NSData" class="headerlink" title="NSData"></a>NSData</h5><h5 id="1-概念"><a href="#1-概念" class="headerlink" title="1.概念"></a>1.概念</h5><blockquote>
<p>NSData为二进制数据，在文件操作（如保存到本地）、网络、以及核心图形图像中使用较广泛。</p>
</blockquote>
<p>源码：</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/****************Base 64 Options****************/</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/*** Base64是一组二进制到文本转化的方案，以ASSCII格式表示二进制数据，这些方案用来编码二进制数据以存储或者通过把多媒体文件转换成文本数据进行传输，这个能保证数据在传输的过程中的完整性。Base64醉常见的用于是处理电子邮件附件，或者解码小图片。在iOS7之前，Base64的编码和解码是需要自己实现的或者是使用第三方库，但是现在苹果提供一些API来实现Base64功能 ***/</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//4.base64编码中的一些设置选择</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="built_in">NS_OPTIONS</span>(<span class="built_in">NSUInteger</span>, <span class="built_in">NSDataBase64EncodingOptions</span>) &#123;</span><br><span class="line">    <span class="built_in">NSDataBase64Encoding64CharacterLineLength</span> = <span class="number">1</span>UL &lt;&lt; <span class="number">0</span>,</span><br><span class="line">    <span class="built_in">NSDataBase64Encoding76CharacterLineLength</span> = <span class="number">1</span>UL &lt;&lt; <span class="number">1</span>,</span><br><span class="line">    <span class="built_in">NSDataBase64EncodingEndLineWithCarriageReturn</span> = <span class="number">1</span>UL &lt;&lt; <span class="number">4</span>,</span><br><span class="line">    <span class="built_in">NSDataBase64EncodingEndLineWithLineFeed</span> = <span class="number">1</span>UL &lt;&lt; <span class="number">5</span>,</span><br><span class="line">&#125; <span class="built_in">NS_ENUM_AVAILABLE</span>(<span class="number">10</span>_9, <span class="number">7</span>_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">//5.base64在解码过程中的option可选条件,下面选项表示在将解码过程中忽略不能识别的字节</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="built_in">NS_OPTIONS</span>(<span class="built_in">NSUInteger</span>, <span class="built_in">NSDataBase64DecodingOptions</span>) &#123;</span><br><span class="line">    <span class="built_in">NSDataBase64DecodingIgnoreUnknownCharacters</span> = <span class="number">1</span>UL &lt;&lt; <span class="number">0</span> </span><br><span class="line">&#125; <span class="built_in">NS_ENUM_AVAILABLE</span>(<span class="number">10</span>_9, <span class="number">7</span>_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/**************** Immutable Data不可变的Data****************/</span></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">NSData</span> : <span class="title">NSObject</span> &lt;<span class="title">NSCopying</span>, <span class="title">NSMutableCopying</span>, <span class="title">NSSecureCoding</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//6.获取data长度的属性</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">readonly</span>) <span class="built_in">NSUInteger</span> length;</span><br><span class="line"></span><br><span class="line"><span class="comment">//7.返回data对象的首指针</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">readonly</span>) <span class="keyword">const</span> <span class="type">void</span> *bytesNS_RETURNS_INNER_POINTER;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">NSData</span> (<span class="title">NSExtendedData</span>)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//8.返回一个ASCII编码格式的字符串，采用的格式是data属性列表的格式。</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">readonly</span>, <span class="keyword">copy</span>) <span class="built_in">NSString</span> *description;</span><br><span class="line"></span><br><span class="line"><span class="comment">//9.取出data中指定长度的字节存入buffer这个提前声明的数组中</span></span><br><span class="line">- (<span class="type">void</span>)getBytes:(<span class="type">void</span> *)buffer length:(<span class="built_in">NSUInteger</span>)length;</span><br><span class="line"></span><br><span class="line"><span class="comment">//9.取出data中指定位置range的字节存入buffer这个提前声明的数组中</span></span><br><span class="line">- (<span class="type">void</span>)getBytes:(<span class="type">void</span> *)buffer range:(<span class="built_in">NSRange</span>)range;</span><br><span class="line"></span><br><span class="line"><span class="comment">//10.判断两个data是否相等</span></span><br><span class="line">- (<span class="type">BOOL</span>)isEqualToData:(<span class="built_in">NSData</span> *)other;</span><br><span class="line"></span><br><span class="line"><span class="comment">//11.截图data指定位置的子data</span></span><br><span class="line">- (<span class="built_in">NSData</span> *)subdataWithRange:(<span class="built_in">NSRange</span>)range;</span><br><span class="line"></span><br><span class="line"><span class="comment">//12.将data写入指定的文件</span></span><br><span class="line">- (<span class="type">BOOL</span>)writeToFile:(<span class="built_in">NSString</span> *)path atomically:(<span class="type">BOOL</span>)useAuxiliaryFile;</span><br><span class="line"></span><br><span class="line"><span class="comment">//13.将data写入指定的url</span></span><br><span class="line">- (<span class="type">BOOL</span>)writeToURL:(<span class="built_in">NSURL</span> *)url atomically:(<span class="type">BOOL</span>)atomically; </span><br><span class="line"></span><br><span class="line"><span class="comment">//14.将data写入指定文件，并且有写入过程的设置条件，带错误信息</span></span><br><span class="line">- (<span class="type">BOOL</span>)writeToFile:(<span class="built_in">NSString</span> *)path options:(<span class="built_in">NSDataWritingOptions</span>)writeOptionsMask error:(<span class="built_in">NSError</span> **)errorPtr;</span><br><span class="line"></span><br><span class="line"><span class="comment">//15.将data写入指定的url，并且有写入过程的设置条件，带错误信息</span></span><br><span class="line">- (<span class="type">BOOL</span>)writeToURL:(<span class="built_in">NSURL</span> *)url options:(<span class="built_in">NSDataWritingOptions</span>)writeOptionsMask error:(<span class="built_in">NSError</span> **)errorPtr;</span><br><span class="line"></span><br><span class="line"><span class="comment">//16.搜索在data1内部存在data2的位置，并且有搜索配置条件，并且可加入搜索的范围</span></span><br><span class="line">- (<span class="built_in">NSRange</span>)rangeOfData:(<span class="built_in">NSData</span> *)dataToFind options:(<span class="built_in">NSDataSearchOptions</span>)mask range:(<span class="built_in">NSRange</span>)searchRange <span class="built_in">NS_AVAILABLE</span>(<span class="number">10</span>_6, <span class="number">4</span>_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">//17.列举遍历字典的方法</span></span><br><span class="line">- (<span class="type">void</span>) enumerateByteRangesUsingBlock:(<span class="type">void</span> (^)(constvoid *bytes, <span class="built_in">NSRange</span> byteRange, <span class="type">BOOL</span> *stop))block <span class="built_in">NS_AVAILABLE</span>(<span class="number">10</span>_9, <span class="number">7</span>_0);</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/*** 创建data的所有相关方法作为一个类别几种到一块 ***/</span></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">NSData</span> (<span class="title">NSDataCreation</span>)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//18.data的快速创建办法</span></span><br><span class="line">+ (<span class="keyword">instancetype</span>)data;</span><br><span class="line"></span><br><span class="line"><span class="comment">//19.赋值以bytes开头，长度为length的数据，进行初始化使其成为数据对象的内容</span></span><br><span class="line">+ (<span class="keyword">instancetype</span>)dataWithBytes:(<span class="keyword">const</span> <span class="type">void</span> *)bytes length:(<span class="built_in">NSUInteger</span>)length;</span><br><span class="line"></span><br><span class="line"><span class="comment">//20.这个方法生成的data中保存的是指向数据的指针，并没有对数据进行复制操作。</span></span><br><span class="line">+ (<span class="keyword">instancetype</span>)dataWithBytesNoCopy:(<span class="type">void</span> *)bytes length:(<span class="built_in">NSUInteger</span>)length;</span><br><span class="line"></span><br><span class="line"><span class="comment">//21.这个方法生成的data中保存的是指向数据的指针，并没有对数据进行复制操作。当flag为yes的时候，生成的data对象是bytes的所有者，当data对象被释放的时候也会同时释放bytes，所以bytes必须是通过malloc在堆上分配的内存。当flag为no的时候，bytes不会被自动释放，释放bytes时要注意时机，不要再data对象还被使用的时候释放bytes。</span></span><br><span class="line">+ (<span class="keyword">instancetype</span>)dataWithBytesNoCopy:(<span class="type">void</span> *)bytes length:(<span class="built_in">NSUInteger</span>)length freeWhenDone:(<span class="type">BOOL</span>)b;</span><br><span class="line"></span><br><span class="line"><span class="comment">//22.加载file文件，并且有可选择读取文件的选项配置条件，带有错误信息</span></span><br><span class="line">+ (<span class="keyword">instancetype</span>)dataWithContentsOfFile:(<span class="built_in">NSString</span> *)path options:(<span class="built_in">NSDataReadingOptions</span>)readOptionsMask error:(<span class="built_in">NSError</span>**)errorPtr;</span><br><span class="line"></span><br><span class="line"><span class="comment">//23.加载url，并且有可选择读取文件的选项配置条件，带有错误信息</span></span><br><span class="line">+ (<span class="keyword">instancetype</span>)dataWithContentsOfURL:(<span class="built_in">NSURL</span> *)url options:(<span class="built_in">NSDataReadingOptions</span>)readOptionsMask error:(<span class="built_in">NSError</span> **)errorPtr;</span><br><span class="line"></span><br><span class="line"><span class="comment">//24.从参数path指定的文件读入二进制数据，用该数据初始化NSData对象。</span></span><br><span class="line">+ (<span class="keyword">instancetype</span>)dataWithContentsOfFile:(<span class="built_in">NSString</span> *)path;</span><br><span class="line"></span><br><span class="line"><span class="comment">//25.从参数path指定的url读入，用该数据初始化NSData对象。</span></span><br><span class="line">+ (<span class="keyword">instancetype</span>)dataWithContentsOfURL:(<span class="built_in">NSURL</span> *)url;</span><br><span class="line"></span><br><span class="line"><span class="comment">//26.赋值以bytes开头，长度为length的数据，进行初始化使其成为数据对象的内容</span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithBytes:(<span class="keyword">const</span> <span class="type">void</span> *)bytes length:(<span class="built_in">NSUInteger</span>)length;</span><br><span class="line"></span><br><span class="line"><span class="comment">//27.这个方法生成的data中保存的是指向数据的指针，并没有对数据进行复制操作。</span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithBytesNoCopy:(<span class="type">void</span> *)bytes length:(<span class="built_in">NSUInteger</span>)length;</span><br><span class="line"></span><br><span class="line"><span class="comment">//28.这个方法生成的data中保存的是指向数据的指针，并没有对数据进行复制操作。当flag为yes的时候，生成的data对象是bytes的所有者，当data对象被释放的时候也会同时释放bytes，所以bytes必须是通过malloc在堆上分配的内存。当flag为no的时候，bytes不会被自动释放，释放bytes时要注意时机，不要再data对象还被使用的时候释放bytes。</span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithBytesNoCopy:(<span class="type">void</span> *)bytes length:(<span class="built_in">NSUInteger</span>)length freeWhenDone:(<span class="type">BOOL</span>)b;</span><br><span class="line"></span><br><span class="line"><span class="comment">//29.</span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithBytesNoCopy:(<span class="type">void</span> *)bytes length:(<span class="built_in">NSUInteger</span>)length deallocator:(<span class="type">void</span> (^)(<span class="type">void</span> *bytes,<span class="built_in">NSUInteger</span> length))deallocator <span class="built_in">NS_AVAILABLE</span>(<span class="number">10</span>_9, <span class="number">7</span>_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">//30.从参数path指定的文件读入二进制数据，用该数据初始化NSData对象。如果读取文件失败，则释放调用者并返回nil，同时把错误信息写入指针errorPtr。mask是一个选项信息，用于指定是否使用虚拟内存等。</span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithContentsOfFile:(<span class="built_in">NSString</span> *)path options:(<span class="built_in">NSDataReadingOptions</span>)readOptionsMask error:(<span class="built_in">NSError</span>**)errorPtr;</span><br><span class="line"></span><br><span class="line"><span class="comment">//31.从参数url指定的路径中读入，用该数据初始化NSData对象。如果读取文件失败，则释放调用者并返回nil，同时把错误信息写入指针errorPtr。mask是一个选项信息，用于指定是否使用虚拟内存等。</span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithContentsOfURL:(<span class="built_in">NSURL</span> *)url options:(<span class="built_in">NSDataReadingOptions</span>)readOptionsMask error:(<span class="built_in">NSError</span> **)errorPtr;</span><br><span class="line"></span><br><span class="line"><span class="comment">//32.加载flie文件路径</span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithContentsOfFile:(<span class="built_in">NSString</span> *)path;</span><br><span class="line"></span><br><span class="line"><span class="comment">//33.加载url</span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithContentsOfURL:(<span class="built_in">NSURL</span> *)url;</span><br><span class="line"></span><br><span class="line"><span class="comment">//34.用指定的NSData对象aData来创建一个新的NSData对象，参数可以是NSMutableData对象。</span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithData:(<span class="built_in">NSData</span> *)data;</span><br><span class="line"></span><br><span class="line"><span class="comment">//35.用指定的NSData对象aData来创建一个新的NSData对象，参数可以是NSMutableData对象。</span></span><br><span class="line">+ (<span class="keyword">instancetype</span>)dataWithData:(<span class="built_in">NSData</span> *)data;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line">  </span><br><span class="line"><span class="comment">/*** base64方案编码分类  iOS7之后苹果给出以下四个API供实现base64方案 头两个是处理字符串的，后两个是处理UTF-8编码数据的，这两个承兑的方法功能是一样的，但是有时候用其中一个比另一个效率要高。如果你像要bae64编码字符串然后写进文件，你应该使用UTF-8编码数据的这对方法。如果你打算base64编码字符串之后用作json，你应该使用另外一对方法 编码解码一一对应***/</span></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">NSData</span> (<span class="title">NSDataBase64Encoding</span>)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//36.解码。将已经base64编码之后的字符串数据再转化为NSData数据，</span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithBase64EncodedString:(<span class="built_in">NSString</span> *)base64String options:(<span class="built_in">NSDataBase64DecodingOptions</span>)optionsNS_AVAILABLE(<span class="number">10</span>_9, <span class="number">7</span>_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">//37.编码。将一个data数据利用base64方案转化成base64之后的NSString字符串</span></span><br><span class="line">- (<span class="built_in">NSString</span> *)base64EncodedStringWithOptions:(<span class="built_in">NSDataBase64EncodingOptions</span>)options <span class="built_in">NS_AVAILABLE</span>(<span class="number">10</span>_9, <span class="number">7</span>_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">//38.解码。将已经base64编码之后的NSData数据再转化为NSData数据</span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithBase64EncodedData:(<span class="built_in">NSData</span> *)base64Data options:(<span class="built_in">NSDataBase64DecodingOptions</span>)optionsNS_AVAILABLE(<span class="number">10</span>_9, <span class="number">7</span>_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">//39.编码.将一个data数据利用base64方案转化成base64之后的NSData数据</span></span><br><span class="line">- (<span class="built_in">NSData</span> *)base64EncodedDataWithOptions:(<span class="built_in">NSDataBase64EncodingOptions</span>)options <span class="built_in">NS_AVAILABLE</span>(<span class="number">10</span>_9, <span class="number">7</span>_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">示例程序：使用第一对编码解码API。</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    NSString * stringExample = [NSString stringWithFormat:@&quot;I Love You&quot;];</span></span><br><span class="line"><span class="comment">    NSData * data1 = [stringExample dataUsingEncoding:NSUTF8StringEncoding];</span></span><br><span class="line"><span class="comment">    </span></span><br><span class="line"><span class="comment">    NSString * base64String   = [data1 base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn];</span></span><br><span class="line"><span class="comment">    NSLog(@&quot;Base64-encoded string is %@&quot;,base64String);</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    //log（Base64-encoded string is SSBMb3ZlIFlvdQ==）；</span></span><br><span class="line"><span class="comment">    NSData * dataFromString = [[NSData alloc] initWithBase64EncodedString:base64String options:NSDataBase64DecodingIgnoreUnknownCharacters];</span></span><br><span class="line"><span class="comment">    NSLog(@&quot;string is %@&quot;,[NSString stringWithUTF8String:[dataFromString bytes]]); </span></span><br><span class="line"><span class="comment">    //log(string is I Love You);</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line">  </span><br><span class="line"><span class="comment">/**************** Mutable Data可变data****************/</span></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">NSMutableData</span> : <span class="title">NSData</span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">//40.可变data的可变字节</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">readonly</span>) <span class="type">void</span> *mutableBytes <span class="built_in">NS_RETURNS_INNER_POINTER</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//41.可变data的长度</span></span><br><span class="line"><span class="keyword">@property</span> <span class="built_in">NSUInteger</span> length;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">NSMutableData</span> (<span class="title">NSExtendedMutableData</span>)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//42.给可变data追加字节</span></span><br><span class="line">- (<span class="type">void</span>)appendBytes:(<span class="keyword">const</span> <span class="type">void</span> *)bytes length:(<span class="built_in">NSUInteger</span>)length;</span><br><span class="line"></span><br><span class="line"><span class="comment">//43.给data追加其他的data</span></span><br><span class="line">- (<span class="type">void</span>)appendData:(<span class="built_in">NSData</span> *)other;</span><br><span class="line"></span><br><span class="line"><span class="comment">//44.为已经存在的data追加新的长度</span></span><br><span class="line">- (<span class="type">void</span>)increaseLengthBy:(<span class="built_in">NSUInteger</span>)extraLength;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">  示例程序：</span></span><br><span class="line"><span class="comment">   </span></span><br><span class="line"><span class="comment">   NSMutableData * data = [NSMutableData data];</span></span><br><span class="line"><span class="comment">   [data increaseLengthBy:5];</span></span><br><span class="line"><span class="comment">   NSLog(@&quot;dataLength———%lu&quot;,(unsigned long)data.length);</span></span><br><span class="line"><span class="comment">   </span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line">     </span><br><span class="line"></span><br><span class="line"><span class="comment">//45.给data替换对应位置的字节</span></span><br><span class="line">- (<span class="type">void</span>)replaceBytesInRange:(<span class="built_in">NSRange</span>)range withBytes:(<span class="keyword">const</span> <span class="type">void</span> *)bytes;</span><br><span class="line"></span><br><span class="line"><span class="comment">//46.重置可变data对应位置的字节</span></span><br><span class="line">- (<span class="type">void</span>)resetBytesInRange:(<span class="built_in">NSRange</span>)range;</span><br><span class="line"></span><br><span class="line"><span class="comment">//47.为可变data设置data数据</span></span><br><span class="line">- (<span class="type">void</span>)setData:(<span class="built_in">NSData</span> *)data;</span><br><span class="line"></span><br><span class="line"><span class="comment">//48.给data替换对应位置的字节, 并且存在替换长度</span></span><br><span class="line">- (<span class="type">void</span>)replaceBytesInRange:(<span class="built_in">NSRange</span>)range withBytes:(<span class="keyword">const</span> <span class="type">void</span> *)replacementBytes length:(<span class="built_in">NSUInteger</span>)replacementLength;</span><br><span class="line"></span><br><span class="line">@end0</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">NSMutableData</span> (<span class="title">NSMutableDataCreation</span>)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//49.动态创建可变data 并且初始化指定大小</span></span><br><span class="line">+ (<span class="keyword">instancetype</span>)dataWithCapacity:(<span class="built_in">NSUInteger</span>)aNumItems;</span><br><span class="line"></span><br><span class="line"><span class="comment">//50.动态创建可变data 并且初始化指定长度</span></span><br><span class="line">+ (<span class="keyword">instancetype</span>)dataWithLength:(<span class="built_in">NSUInteger</span>)length;</span><br><span class="line"></span><br><span class="line"><span class="comment">//51.静态创建可变data 并且初始化指定大小</span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithCapacity:(<span class="built_in">NSUInteger</span>)capacity;</span><br><span class="line"></span><br><span class="line"><span class="comment">//52.静态创建可变data 并且初始化指定长度 </span></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithLength:(<span class="built_in">NSUInteger</span>)length;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//1.data读取过程的可选配置条件</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="built_in">NS_OPTIONS</span>(<span class="built_in">NSUInteger</span>, <span class="built_in">NSDataReadingOptions</span>) &#123;</span><br><span class="line">    <span class="built_in">NSDataReadingMappedIfSafe</span> =   <span class="number">1</span>UL &lt;&lt; <span class="number">0</span>,    <span class="built_in">NSDataReadingUncached</span> = <span class="number">1</span>UL &lt;&lt; <span class="number">1</span>,</span><br><span class="line"></span><br><span class="line">    <span class="built_in">NSDataReadingMappedAlways</span> <span class="built_in">NS_ENUM_AVAILABLE</span>(<span class="number">10</span>_7, <span class="number">5</span>_0) = <span class="number">1</span>UL &lt;&lt; <span class="number">3</span>,</span><br><span class="line"></span><br><span class="line">       <span class="built_in">NSDataReadingMapped</span> = <span class="built_in">NSDataReadingMappedIfSafe</span>,<span class="comment">// Deprecated name for NSDataReadingMappedIfSafe</span></span><br><span class="line"></span><br><span class="line">    <span class="built_in">NSMappedRead</span> = <span class="built_in">NSDataReadingMapped</span>,<span class="comment">// Deprecated name for NSDataReadingMapped</span></span><br><span class="line"></span><br><span class="line">    <span class="built_in">NSUncachedRead</span> = <span class="built_in">NSDataReadingUncached</span><span class="comment">// Deprecated name for NSDataReadingUncached</span></span><br><span class="line"></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">//2.data写入过程的可选配置条件</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="built_in">NS_OPTIONS</span>(<span class="built_in">NSUInteger</span>, <span class="built_in">NSDataWritingOptions</span>) &#123;</span><br><span class="line">    <span class="built_in">NSDataWritingAtomic</span> = <span class="number">1</span>UL &lt;&lt; <span class="number">0</span>,</span><br><span class="line"></span><br><span class="line">    <span class="built_in">NSDataWritingWithoutOverwriting</span> <span class="built_in">NS_ENUM_AVAILABLE</span>(<span class="number">10</span>_8, <span class="number">6</span>_0) = <span class="number">1</span>UL &lt;&lt; <span class="number">1</span>, </span><br><span class="line"></span><br><span class="line">    <span class="built_in">NSDataWritingFileProtectionNoneNS_ENUM_AVAILABLE_IOS</span>(<span class="number">4</span>_0)                                  = <span class="number">0x10000000</span>,</span><br><span class="line"></span><br><span class="line">    <span class="built_in">NSDataWritingFileProtectionCompleteNS_ENUM_AVAILABLE_IOS</span>(<span class="number">4</span>_0)                              =<span class="number">0x20000000</span>,</span><br><span class="line"></span><br><span class="line">    <span class="built_in">NSDataWritingFileProtectionCompleteUnlessOpenNS_ENUM_AVAILABLE_IOS</span>(<span class="number">5</span>_0)                    = <span class="number">0x30000000</span>,</span><br><span class="line"></span><br><span class="line">    <span class="built_in">NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication</span> <span class="built_in">NS_ENUM_AVAILABLE_IOS</span>(<span class="number">5</span>_0)  = <span class="number">0x40000000</span>,</span><br><span class="line"></span><br><span class="line">    <span class="built_in">NSDataWritingFileProtectionMaskNS_ENUM_AVAILABLE_IOS</span>(<span class="number">4</span>_0)                                  = <span class="number">0xf0000000</span>,</span><br><span class="line"></span><br><span class="line">    <span class="built_in">NSAtomicWrite</span> = <span class="built_in">NSDataWritingAtomic</span> </span><br><span class="line"> &#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**************** Data Search Options****************/</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//3.data在搜索过程中的可选配置条件</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="built_in">NS_OPTIONS</span>(<span class="built_in">NSUInteger</span>, <span class="built_in">NSDataSearchOptions</span>) &#123;</span><br><span class="line">    <span class="built_in">NSDataSearchBackwards</span> = <span class="number">1</span>UL &lt;&lt; <span class="number">0</span>,</span><br><span class="line">    <span class="built_in">NSDataSearchAnchored</span> = <span class="number">1</span>UL &lt;&lt; <span class="number">1</span></span><br><span class="line">&#125; <span class="built_in">NS_ENUM_AVAILABLE</span>(<span class="number">10</span>_6, <span class="number">4</span>_0);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">/****************     Purgeable Data****************/</span></span><br><span class="line"><span class="built_in">NS_CLASS_AVAILABLE</span>(<span class="number">10</span>_6, <span class="number">4</span>_0)</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">NSPurgeableData</span> : <span class="title">NSMutableData</span> &lt;<span class="title">NSDiscardableContent</span>&gt; </span>&#123;</span><br><span class="line"><span class="keyword">@private</span></span><br><span class="line"></span><br><span class="line">    <span class="built_in">NSUInteger</span> _length;</span><br><span class="line"></span><br><span class="line">    int32_t _accessCount;</span><br><span class="line"></span><br><span class="line">    uint8_t _private[<span class="number">32</span>];</span><br><span class="line"></span><br><span class="line">    <span class="type">void</span> *_reserved;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<hr>
<h6 id="2-创建方式"><a href="#2-创建方式" class="headerlink" title="2.创建方式"></a>2.创建方式</h6><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//对象方法创建</span></span><br><span class="line">  <span class="built_in">NSData</span> *data1 = [[<span class="built_in">NSData</span> alloc] init]; <span class="comment">//Initialize an empty `Data`</span></span><br><span class="line">  <span class="built_in">NSData</span> *data2 = [[<span class="built_in">NSData</span> alloc] initWithData:data1];</span><br><span class="line"></span><br><span class="line">  <span class="comment">//类方法创建</span></span><br><span class="line">  <span class="built_in">NSData</span> *data3 = [<span class="built_in">NSData</span> data];</span><br><span class="line">  <span class="built_in">NSData</span> *data4 = [<span class="built_in">NSData</span> dataWithData:data3];</span><br><span class="line"></span><br><span class="line">  <span class="comment">//由文件创建</span></span><br><span class="line">  <span class="built_in">NSString</span> *filePath = [<span class="built_in">NSHomeDirectory</span>() stringByAppendingString:<span class="string">@&quot;/Desktop/test.txt&quot;</span>];  </span><br><span class="line">  <span class="built_in">NSData</span> *data5 = [[<span class="built_in">NSData</span> alloc] initWithContentsOfFile:filePath];</span><br><span class="line">  <span class="built_in">NSData</span> *data6 = [<span class="built_in">NSData</span> dataWithContentsOfFile:filePath];</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 由 URL 创建</span></span><br><span class="line">  <span class="built_in">NSURL</span> *urlPath = [<span class="built_in">NSURL</span> URLWithString:[<span class="string">@&quot;file://&quot;</span> stringByAppendingString:[<span class="built_in">NSHomeDirectory</span>() stringByAppendingString:<span class="string">@&quot;/Desktop/test.txt&quot;</span>]]];</span><br><span class="line">  <span class="built_in">NSData</span> *data7 = [[<span class="built_in">NSData</span> alloc] initWithContentsOfURL:urlPath];</span><br><span class="line">  <span class="built_in">NSData</span> *data8 = [<span class="built_in">NSData</span> dataWithContentsOfURL:urlPath];</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 由 字符串 创建</span></span><br><span class="line">  <span class="built_in">NSString</span> *string = <span class="string">@&quot;bei jing nin hao&quot;</span>;</span><br><span class="line">  <span class="built_in">NSData</span> *data9 = [string dataUsingEncoding:<span class="built_in">NSUTF8StringEncoding</span>];</span><br><span class="line">  <span class="built_in">NSData</span> *data10 = [string dataUsingEncoding:<span class="built_in">NSUTF8StringEncoding</span> allowLossyConversion:<span class="literal">YES</span>];</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 可变 NSData 的创建</span></span><br><span class="line">  <span class="comment">// 初始化时指定对象拥有的字节空间大小，在需要时会增加内存空间，在初始化时并没有分配内存空间</span></span><br><span class="line">  <span class="built_in">NSMutableData</span> *data11 = [[<span class="built_in">NSMutableData</span> alloc] initWithCapacity:<span class="number">5</span>];</span><br><span class="line">  <span class="built_in">NSMutableData</span> *data12 = [<span class="built_in">NSMutableData</span> dataWithCapacity:<span class="number">5</span>];</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 初始化时为对象分配指定长度的归零字节</span></span><br><span class="line">  <span class="built_in">NSMutableData</span> *data13 = [[<span class="built_in">NSMutableData</span> alloc] initWithLength:<span class="number">10</span>];</span><br><span class="line">  <span class="built_in">NSMutableData</span> *data14 = [<span class="built_in">NSMutableData</span> dataWithLength:<span class="number">10</span>];</span><br></pre></td></tr></table></figure>



<h6 id="3-NSData与NSString、Byte、UIImage之间的转换"><a href="#3-NSData与NSString、Byte、UIImage之间的转换" class="headerlink" title="3.NSData与NSString、Byte、UIImage之间的转换"></a>3.NSData与NSString、Byte、UIImage之间的转换</h6><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//NSString 转换成 NSData</span></span><br><span class="line">  <span class="built_in">NSString</span> *str = <span class="string">@&quot;Hello&quot;</span>;</span><br><span class="line">  <span class="built_in">NSData</span> *strData = [str dataUsingEncoding:<span class="built_in">NSUTF8StringEncoding</span>];</span><br><span class="line"></span><br><span class="line">  <span class="comment">//NSData 转换成 NSString</span></span><br><span class="line">  <span class="built_in">NSString</span> *str1 = [[<span class="built_in">NSString</span> alloc]initWithData:strData encoding:<span class="built_in">NSUTF8StringEncoding</span>];</span><br><span class="line"></span><br><span class="line">  <span class="comment">//Byte 转换成 NSData</span></span><br><span class="line">  Byte byte[] = &#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>,<span class="number">8</span>,<span class="number">9</span>,<span class="number">10</span>&#125;;  </span><br><span class="line">  <span class="built_in">NSData</span> *byteData = [[<span class="built_in">NSData</span> alloc] initWithBytes:byte length:<span class="number">10</span>];</span><br><span class="line"></span><br><span class="line">  <span class="comment">//NSData 转换成 Byte </span></span><br><span class="line">  Byte *testByte = (Byte *)[byteData bytes]; </span><br><span class="line"></span><br><span class="line">  <span class="comment">//UIImage 转换成 NSData</span></span><br><span class="line">  <span class="built_in">NSData</span> *imageData1 = <span class="built_in">UIImagePNGRepresentation</span>(<span class="built_in">UIImage</span> *image);     <span class="comment">//png 格式 </span></span><br><span class="line">  <span class="built_in">NSData</span> *imageData2 = <span class="built_in">UIImageJPEGRepresentation</span>(<span class="built_in">UIImage</span> *image, <span class="built_in">CGFloat</span> compressionQuality)  <span class="comment">//jpeg格式  </span></span><br><span class="line"></span><br><span class="line">  <span class="comment">//NSData 转换成 UIImage</span></span><br><span class="line">  <span class="built_in">UIImage</span> *aimage = [<span class="built_in">UIImage</span> imageWithData: imageData]; </span><br><span class="line">  </span><br></pre></td></tr></table></figure>



<h5 id="4-NSMutableData删除部分数据"><a href="#4-NSMutableData删除部分数据" class="headerlink" title="4.NSMutableData删除部分数据"></a>4.NSMutableData删除部分数据</h5><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">    Byte byte[] = &#123;<span class="number">1</span>, <span class="number">2</span> , <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>&#125;;</span><br><span class="line">    <span class="built_in">NSMutableData</span> *dataM = [[<span class="built_in">NSMutableData</span> alloc] initWithBytes:byte length:<span class="number">5</span>];</span><br><span class="line">    <span class="built_in">NSLog</span>(<span class="string">@&quot;原数据 length:%d, dataM:%@&quot;</span>, (<span class="type">int</span>)dataM.length, dataM);</span><br><span class="line">    [dataM resetBytesInRange:<span class="built_in">NSMakeRange</span>(<span class="number">0</span>, <span class="number">3</span>)];                                <span class="comment">// 替换成0, 长度不变</span></span><br><span class="line">    <span class="built_in">NSLog</span>(<span class="string">@&quot;reset操作 length:%d, dataM:%@&quot;</span>, (<span class="type">int</span>)dataM.length, dataM);</span><br><span class="line">    [dataM replaceBytesInRange:<span class="built_in">NSMakeRange</span>(<span class="number">0</span>, <span class="number">2</span>) withBytes:<span class="literal">NULL</span> length:<span class="number">0</span>];      <span class="comment">// 长度改变, 真正删除</span></span><br><span class="line">    <span class="built_in">NSLog</span>(<span class="string">@&quot;replace操作 length:%d, dataM:%@&quot;</span>, (<span class="type">int</span>)dataM.length, dataM);删除</span><br><span class="line">    <span class="built_in">NSLog</span>(<span class="string">@&quot;replace操作 length:%d, dataM:%@&quot;</span>, (<span class="type">int</span>)dataM.length, dataM);</span><br><span class="line"></span><br><span class="line">log:</span><br><span class="line">原数据 length:<span class="number">5</span>, dataM:&#123;length = <span class="number">5</span>, bytes = <span class="number">0x0102030405</span>&#125;</span><br><span class="line">reset操作 length:<span class="number">5</span>, dataM:&#123;length = <span class="number">5</span>, bytes = <span class="number">0x0000000405</span>&#125;</span><br><span class="line">replace操作 length:<span class="number">3</span>, dataM:&#123;length = <span class="number">3</span>, bytes = <span class="number">0x000405</span>&#125;</span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Albert Yuan</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://yllove.gitee.io/2021/12/10/iOS/NSData%E7%90%86%E8%A7%A3%E4%B8%8E%E8%BF%9B%E9%98%B6/">https://yllove.gitee.io/2021/12/10/iOS/NSData%E7%90%86%E8%A7%A3%E4%B8%8E%E8%BF%9B%E9%98%B6/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://yllove.gitee.io" target="_blank">Albert Yuan's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/iOS/">iOS</a></div><div class="post_share"><div class="social-share" data-image="/blog/img/defaultCover.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://fastly.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://fastly.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2021/12/09/Swift/Swift-JSONSerialization%E7%B1%BB%E8%AF%A6%E8%A7%A3/"><img class="prev-cover" src= "" data-lazy-src="/blog/img/defaultCover.png" onerror="onerror=null;src='/blog/img/defaultCover.gif'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Swift-JSONSerialization类详解</div></div></a></div><div class="next-post pull-right"><a href="/blog/2021/12/10/Swift/swift%E6%95%B0%E6%8D%AE%E8%A7%A3%E6%9E%90%E6%96%B9%E6%A1%88%E5%AF%B9%E6%AF%94/"><img class="next-cover" src= "" data-lazy-src="/blog/img/defaultCover.png" onerror="onerror=null;src='/blog/img/defaultCover.gif'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">swift数据解析方案对比</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/2021/09/26/iOS UIKIt/UIDynamic动态物理引擎/" title="UIDynamic动态物理引擎"><img class="cover" src= "" data-lazy-src="https://img0.baidu.com/it/u=1254289242,26520186&fm=26&fmt=auto" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-26</div><div class="title">UIDynamic动态物理引擎</div></div></a></div><div><a href="/blog/2021/09/08/iOS UIKIt/UIViewContentMode属性详解/" title="UIViewContentMode属性详解"><img class="cover" src= "" data-lazy-src="https://img1.baidu.com/it/u=2815189064,4171169784&fm=26&fmt=auto&gp=0.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-08</div><div class="title">UIViewContentMode属性详解</div></div></a></div><div><a href="/blog/2021/09/24/iOS UIKIt/iOSUIKit之UIWindow详解/" title="iOSUIKit之UIWindow详解"><img class="cover" src= "" data-lazy-src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimages2018.cnblogs.com%2Fblog%2F749924%2F201807%2F749924-20180730112644434-125751676.png&refer=http%3A%2F%2Fimages2018.cnblogs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1635046008&t=fd235aaa9fc1476b26197b2443c90864" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-24</div><div class="title">iOSUIKit之UIWindow详解</div></div></a></div><div><a href="/blog/2021/08/11/iOS UIKIt/iOSUITabBarContrller详解/" title="iOSUITabBarContrller详解与使用"><img class="cover" src= "" data-lazy-src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimages2015.cnblogs.com%2Fblog%2F877749%2F201602%2F877749-20160202134709194-1710798604.png&refer=http%3A%2F%2Fimages2015.cnblogs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1631242411&t=6c8a605550b8da493ae89b30e55f1a65" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-08-11</div><div class="title">iOSUITabBarContrller详解与使用</div></div></a></div><div><a href="/blog/2021/10/27/iOS UIKIt/iOS导航栏遮挡问题的总结/" title="iOS导航栏遮挡问题的总结"><img class="cover" src= "" data-lazy-src="/blog/img/defaultCover.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-27</div><div class="title">iOS导航栏遮挡问题的总结</div></div></a></div><div><a href="/blog/2021/10/11/iOS UIKIt/iosUIButton自定义图片title位置/" title="iosUIButton自定义图片title位置"><img class="cover" src= "" data-lazy-src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fstatic.17ky.net%2FImages%2F20170529%2F0ba4fd793eeb6bc60d701465ecb80e5b.png&refer=http%3A%2F%2Fstatic.17ky.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1636515244&t=7ff70a346e0f2bb2f2c6537f024d404d" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-11</div><div class="title">iosUIButton自定义图片title位置</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="/blog/img/favicon.png" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Albert Yuan</div><div class="author-info__description">博学之,审问之,慎思之,明辨之,笃行之</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">155</div></a></div><div class="card-info-data-item is-center"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">56</div></a></div><div class="card-info-data-item is-center"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">32</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/yuanliangYL"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/yuanliangYL" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:yuanliangios@163.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="qq:1023817403" target="_blank" title="QQ"><i class="fab fa-qq"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">love cat , love life</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#NSData"><span class="toc-text">NSData</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#1-%E6%A6%82%E5%BF%B5"><span class="toc-text">1.概念</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#2-%E5%88%9B%E5%BB%BA%E6%96%B9%E5%BC%8F"><span class="toc-text">2.创建方式</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#3-NSData%E4%B8%8ENSString%E3%80%81Byte%E3%80%81UIImage%E4%B9%8B%E9%97%B4%E7%9A%84%E8%BD%AC%E6%8D%A2"><span class="toc-text">3.NSData与NSString、Byte、UIImage之间的转换</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-NSMutableData%E5%88%A0%E9%99%A4%E9%83%A8%E5%88%86%E6%95%B0%E6%8D%AE"><span class="toc-text">4.NSMutableData删除部分数据</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2023/02/07/iOS%E5%BC%80%E5%8F%91%E8%BF%9B%E9%98%B6/iOS-%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BD%91%E9%A1%B5%E4%B8%8B%E8%BD%BDIPA%E5%8C%85/" title="iOS 自定义网页下载IPA包"><img src= "" data-lazy-src="https://img.mp.itc.cn/upload/20170409/1a8f793d7282451cbd1beb6841608c90_th.jpeg" onerror="this.onerror=null;this.src='/blog/img/defaultCover.gif'" alt="iOS 自定义网页下载IPA包"/></a><div class="content"><a class="title" href="/blog/2023/02/07/iOS%E5%BC%80%E5%8F%91%E8%BF%9B%E9%98%B6/iOS-%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BD%91%E9%A1%B5%E4%B8%8B%E8%BD%BDIPA%E5%8C%85/" title="iOS 自定义网页下载IPA包">iOS 自定义网页下载IPA包</a><time datetime="2023-02-07T02:46:29.851Z" title="更新于 2023-02-07 10:46:29">2023-02-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2023/02/06/Flutter/Flutter%E6%8E%A5%E5%85%A5%E5%8E%9F%E7%94%9F-iOS/" title="flutter接入原生-iOS"><img src= "" data-lazy-src="https://pic4.zhimg.com/v2-6a115fea4db1ad770dccf4119bfab36f_1440w.jpg?source=172ae18b" onerror="this.onerror=null;this.src='/blog/img/defaultCover.gif'" alt="flutter接入原生-iOS"/></a><div class="content"><a class="title" href="/blog/2023/02/06/Flutter/Flutter%E6%8E%A5%E5%85%A5%E5%8E%9F%E7%94%9F-iOS/" title="flutter接入原生-iOS">flutter接入原生-iOS</a><time datetime="2023-02-07T01:18:53.661Z" title="更新于 2023-02-07 09:18:53">2023-02-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/12/17/iOS%E5%BC%80%E5%8F%91%E8%BF%9B%E9%98%B6/iOS%20%E5%A6%82%E4%BD%95%E5%9C%A8%E6%A8%A1%E6%8B%9F%E5%99%A8%E4%B8%AD%E5%AE%89%E8%A3%85APP/" title="iOS 如何在模拟器中安装APP"><img src= "" data-lazy-src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.winwin7.com%2Fuploadfile%2F2021%2F0114%2F20210114141748239.jpg&amp;refer=http%3A%2F%2Fwww.winwin7.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1673854539&amp;t=aad2108ffb799b04e94a28cc58f038f1" onerror="this.onerror=null;this.src='/blog/img/defaultCover.gif'" alt="iOS 如何在模拟器中安装APP"/></a><div class="content"><a class="title" href="/blog/2022/12/17/iOS%E5%BC%80%E5%8F%91%E8%BF%9B%E9%98%B6/iOS%20%E5%A6%82%E4%BD%95%E5%9C%A8%E6%A8%A1%E6%8B%9F%E5%99%A8%E4%B8%AD%E5%AE%89%E8%A3%85APP/" title="iOS 如何在模拟器中安装APP">iOS 如何在模拟器中安装APP</a><time datetime="2022-12-17T07:48:56.594Z" title="更新于 2022-12-17 15:48:56">2022-12-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/08/05/Swift/swift%E5%B8%B8%E7%94%A8%E4%B8%89%E6%96%B9%E5%BA%93/" title="swift常用三方库"><img src= "" data-lazy-src="https://photos.infinum.com/store/b558bd40787ecad225d9c66322f14522" onerror="this.onerror=null;this.src='/blog/img/defaultCover.gif'" alt="swift常用三方库"/></a><div class="content"><a class="title" href="/blog/2021/08/05/Swift/swift%E5%B8%B8%E7%94%A8%E4%B8%89%E6%96%B9%E5%BA%93/" title="swift常用三方库">swift常用三方库</a><time datetime="2022-12-16T06:37:20.115Z" title="更新于 2022-12-16 14:37:20">2022-12-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/12/12/iOS%E5%BC%80%E5%8F%91%E8%BF%9B%E9%98%B6/GCD%E8%BF%9B%E9%98%B6%E4%B9%8BDispatchWorkItem%E5%92%8CDispatchGroup/" title="GCD进阶之DispatchWorkItem和DispatchGroup"><img src= "" data-lazy-src="/blog/img/defaultCover.png" onerror="this.onerror=null;this.src='/blog/img/defaultCover.gif'" alt="GCD进阶之DispatchWorkItem和DispatchGroup"/></a><div class="content"><a class="title" href="/blog/2022/12/12/iOS%E5%BC%80%E5%8F%91%E8%BF%9B%E9%98%B6/GCD%E8%BF%9B%E9%98%B6%E4%B9%8BDispatchWorkItem%E5%92%8CDispatchGroup/" title="GCD进阶之DispatchWorkItem和DispatchGroup">GCD进阶之DispatchWorkItem和DispatchGroup</a><time datetime="2022-12-12T07:19:37.277Z" title="更新于 2022-12-12 15:19:37">2022-12-12</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/blog/img/defaultCover.png')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By Albert Yuan</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi, welcom to my  blog</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="algolia-search"><div class="search-dialog"><div class="search-dialog__title" id="algolia-search-title">Algolia</div><div id="algolia-input-panel"><div id="algolia-search-input"></div></div><hr/><div id="algolia-search-results"><div id="algolia-hits"></div><div id="algolia-pagination"></div><div id="algolia-stats"></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="https://fastly.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/blog/js/search/algolia.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>if (!window.MathJax) {
  window.MathJax = {
    tex: {
      inlineMath: [ ['$','$'], ["\\(","\\)"]],
      tags: 'ams'
    },
    chtml: {
      scale: 1.2
    },
    options: {
      renderActions: {
        findScript: [10, doc => {
          for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
            const display = !!node.type.match(/; *mode=display/)
            const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
            const text = document.createTextNode('')
            node.parentNode.replaceChild(text, node)
            math.start = {node: text, delim: '', n: 0}
            math.end = {node: text, delim: '', n: 0}
            doc.math.push(math)
          }
        }, ''],
        insertScript: [200, () => {
          document.querySelectorAll('mjx-container:not\([display]\)').forEach(node => {
            const target = node.parentNode
            if (target.nodeName.toLowerCase() === 'li') {
              target.parentNode.classList.add('has-jax')
            } else {
              target.classList.add('has-jax')
            }
          });
        }, '', false]
      }
    }
  }
  
  const script = document.createElement('script')
  script.src = 'https://fastly.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'
  script.id = 'MathJax-script'
  script.async = true
  document.head.appendChild(script)
} else {
  MathJax.startup.document.state(0)
  MathJax.texReset()
  MathJax.typeset()
}</script><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'REc8eytE1gJDl3d8FkudLNlL-gzGzoHsz',
      appKey: 'gGO3y8I9oVlc4Cd5N1fizNPW',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://fastly.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://fastly.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script id="canvas_nest" defer="defer" color="255,0,0" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://fastly.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script src="https://fastly.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = true;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://fastly.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="false"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>